package com.hiultra.archive.controller;

import com.hiultra.archive.domain.ArcBorrowDetails;
import com.hiultra.archive.service.IArcBorrowDetailsService;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.core.page.TableDataInfo;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 借阅详情Controller
 * 
 * @author ls
 * @date 2022-07-28
 */
@RestController
@RequestMapping("/borrow/details")
public class ArcBorrowDetailsController extends BaseController
{
    @Autowired
    private IArcBorrowDetailsService arcBorrowDetailsService;

    /**
     * 查询借阅详情列表
     */
    @PreAuthorize("@ss.hasPermi('borrow:details:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArcBorrowDetails arcBorrowDetails)
    {
        startPage();
        List<ArcBorrowDetails> list = arcBorrowDetailsService.selectArcBorrowDetailsList(arcBorrowDetails);
        return getDataTable(list);
    }

    /**
     * 导出借阅详情列表
     */
    @PreAuthorize("@ss.hasPermi('borrow:details:export')")
    @Log(title = "借阅详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArcBorrowDetails arcBorrowDetails)
    {
        List<ArcBorrowDetails> list = arcBorrowDetailsService.selectArcBorrowDetailsList(arcBorrowDetails);
        ExcelUtil<ArcBorrowDetails> util = new ExcelUtil<ArcBorrowDetails>(ArcBorrowDetails.class);
        util.exportExcel(response, list, "借阅详情数据");
    }

    /**
     * 获取借阅详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('borrow:details:query')")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return AjaxResult.success(arcBorrowDetailsService.selectArcBorrowDetailsByDetailId(detailId));
    }

    /**
     * 新增借阅详情
     */
    @PreAuthorize("@ss.hasPermi('borrow:details:add')")
    @Log(title = "借阅详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArcBorrowDetails arcBorrowDetails)
    {
        return toAjax(arcBorrowDetailsService.insertArcBorrowDetails(arcBorrowDetails));
    }

    /**
     * 修改借阅详情
     */
    @PreAuthorize("@ss.hasPermi('borrow:details:edit')")
    @Log(title = "借阅详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArcBorrowDetails arcBorrowDetails)
    {
        return toAjax(arcBorrowDetailsService.updateArcBorrowDetails(arcBorrowDetails));
    }

    /**
     * 删除借阅详情
     */
    @PreAuthorize("@ss.hasPermi('borrow:details:remove')")
    @Log(title = "借阅详情", businessType = BusinessType.DELETE)
	@PostMapping("/return")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(arcBorrowDetailsService.deleteArcBorrowDetailsByDetailIds(detailIds));
    }

}
